﻿//===========================[ 8 / 7 / 2011 LVI ]=============================
//				Copyright c Vitaly Lyaschenko <SkyChameleon@gmail.com>
//								Source file
// Purpose: парсинг конфигурационного файла
//=============================================================================
#include "cConfig.h"
#include "Kernel.h"

cLuaScript   *cParserCfg::m_Script;
DisplayCfg   *cParserCfg::m_RenderCfg;
std::string   cParserCfg::nameApp;

cParserCfg::cParserCfg()
{   
    m_Script = NULL;
    m_RenderCfg = NULL;
}

cParserCfg::~cParserCfg()
{
    m_Script = NULL;
    SAFE_DELETE( m_RenderCfg );
}

bool cParserCfg::init( const char* config )
{
    if ( !config )
    {
        cwLogger::writeERROR( "Wrong Config File!" );
        return false;
    }

    m_Script = Kernel::spec().getScript();
    if ( !m_Script )
        return false;

    m_RenderCfg = new DisplayCfg;

    if ( !m_RenderCfg )
        return false;

    m_Script->doScript( config );

    m_RenderCfg->width       = m_Script->getGlobalI("width"       );
    m_RenderCfg->height      = m_Script->getGlobalI("height"      );
    m_RenderCfg->frequency   = m_Script->getGlobalI("frequency"   );
    m_RenderCfg->fullScreen  = m_Script->getGlobalI("fullscreen"  );
    m_RenderCfg->showCursor  = m_Script->getGlobalI("showCursor"  );
    m_RenderCfg->antialiasing= m_Script->getGlobalI("antialiasing");

    cFileManager::regiserPath( m_Script->getGlobalS("path_Data"  ));
    cFileManager::regiserPath( m_Script->getGlobalS("path_Entity"));
    cFileManager::regiserPath( m_Script->getGlobalS("path_Effect"));
    cFileManager::regiserPath( m_Script->getGlobalS("path_Res"   ));

    //cFileManager::regiserPath( m_Script->getGlobalS("path_Meshes") );
    //cFileManager::regiserPath( m_Script->getGlobalS("path_Images") );
    //cFileManager::regiserPath( m_Script->getGlobalS("path_ShaderV") );
    //cFileManager::regiserPath( m_Script->getGlobalS("path_ShaderF") );

    nameApp = m_Script->getGlobalS( "name" );

return true;
}